package com.bilubi.reggie.reggie.controller;

import com.bilubi.reggie.reggie.bean.Setmeal;
import com.bilubi.reggie.reggie.bean.SetmealDish;
import com.bilubi.reggie.reggie.bean.vo.SetmealVo;
import com.bilubi.reggie.reggie.common.R;
import com.bilubi.reggie.reggie.service.SetmealService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public R<PageInfo<?>> getSetmeals(@RequestParam(value = "page") Integer page,
                                      @RequestParam(value = "pageSize") Integer pageSize,
                                      @RequestParam(value = "name", defaultValue = "", required = false) String name) {
        PageHelper.startPage(page, pageSize);
        List<SetmealVo> setmealVos = setmealService.selectAll(name);
        PageInfo<SetmealVo> pageInfo = new PageInfo<>(setmealVos);
        return R.success(pageInfo);
    }

    @RequestMapping(method = RequestMethod.POST)
    public R<String> addSetmeal(@RequestBody SetmealVo setmealVo) {
        setmealService.insertSetmeal(setmealVo);
        return R.success();
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public R<SetmealVo> getSetmealById(@PathVariable(value = "id") Long id) {
        SetmealVo setmealVo = setmealService.selectSetmealById(id);
        return R.success(setmealVo);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public R<String> updateSetmeal(@RequestBody SetmealVo setmealVo) {
        setmealService.updateSetmeal(setmealVo);
        return R.success();
    }

    @RequestMapping(value = "/status/{status}", method = RequestMethod.POST)
    public R<String> stopOrStartSetmeal(@PathVariable(value = "status") Integer status, @RequestParam(value = "ids") String ids) {
        setmealService.updateStatusById(status, ids);
        return R.success();
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public R<String> deleteSetmealById(@RequestParam(value = "ids") String ids) {
        setmealService.deleteById(ids);
        return R.success();
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R<List<Setmeal>> selectSetmealByCategoryId(@RequestParam(value = "categoryId") Long categoryId){
        List<Setmeal> setmeals = setmealService.selectSetmealByCategoryId(categoryId);
        return R.success(setmeals);
    }


}
